﻿

using System;

using ARCHFORME.Common;
using ARCHFORME.Core;

using Autofac;

using FakeItEasy;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Core.Tests.Querying
{
    [TestClass]
    public class QueryProcessorSpecs
    {
        [TestMethod]
        public void When_given_a_query_it_should_find_a_handler_to_excute_query()
        {
            /********* Arrange ********************/
            var query = new DummyQuery();
            var handler = A.Fake<IHandleQueries<DummyQuery, DummyResult>>();
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterInstance<IHandleQueries<DummyQuery, DummyResult>>(handler);
            Ioc.Global = containerBuilder.Build();
            
            var processor = new QueryProcessor();

            /********* Act     ********************/
            processor.Process(query);

            /********* Assert  ********************/
            A.CallTo(() => handler.Handle(query)).MustHaveHappened();
        }
    }
}
